package com.lxk.concurrency.example.atomic;

import java.util.concurrent.atomic.AtomicReference;

import com.lxk.concurrency.annoations.ThreadSafe;

/**
 * @Description 原子性的赋值操作，可以使用 AtomicReference
 *
 * @author 堆堆堆
 * @date 2018年5月25日 下午5:24:04
 */
@ThreadSafe
public class AtomicExample4 {

	private static AtomicReference<Integer> count = new AtomicReference<Integer>(0);

	public static void main(String[] args) {

		count.compareAndSet(0, 2); // 2
		count.compareAndSet(0, 1); // no
		count.compareAndSet(1, 3); // no
		count.compareAndSet(2, 4); // 4
		count.compareAndSet(3, 5); // no

		System.out.println("count:" + count.get());
	}
}
